package com.taotao.frame.common.redis;

import java.util.Random;

/**
 * <p>
 * 集中管理redis的key
 * </p>
 *
 * @author fanbeibei
 * @version V1.0
 * @since 2019/9/8 10:45
 */
public class RedisKeys {
    public static final String COMMMON_PRIFFIX = "auth-center:";
    public static final String SYSACCOUNT_PRIFFIX = COMMMON_PRIFFIX + "account:";
    public static final String LOGIC_AUTH_PRIFFIX = COMMMON_PRIFFIX + "logic-auth:";
    public static final String LOGIN_USER_INFO_PRIFFIX = COMMMON_PRIFFIX + "user-info:";

    private RedisKeys() {
    }


    /**
     * 缓存系统账号信息的key
     *
     * @param account 账号
     * @return
     */
    public static String getSysAccountInfoKey(String account) {
        return SYSACCOUNT_PRIFFIX + account;
    }

    /**
     * 缓存系统账号逻辑权限信息的key
     *
     * @param systemCode 系统编码
     * @param account    账号
     * @return
     */
    public static String getLogicAuthInfoKey(String systemCode, String account) {
        return LOGIC_AUTH_PRIFFIX + systemCode + ":" + account;
    }


    /**
     * 登录信息的key
     *
     * @param token 登录的token
     * @return
     */
    public static String getLoginUserInfoKey(String token) {
        return LOGIN_USER_INFO_PRIFFIX + token;
    }


    /**
     * 防止雪崩
     *
     * @param expireTime
     * @return
     */
    public static long getExpireTime(long expireTime) {
        return expireTime + new Random().nextInt(60 * 2);
    }
}
